package com.intellij.licensecommon.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    private static final String FORMAT = "yyyyMMdd";

    public static int encode(Date date) {
        return Integer.valueOf(new SimpleDateFormat(FORMAT).format(date)).intValue();
    }

    public static Date decode(int date) {
        try {
            return new SimpleDateFormat(FORMAT).parse(Integer.toString(date));
        } catch (ParseException localParseException) {
            throw new IllegalArgumentException("Could not retrieve date form version. Accepted only: yyyyMMdd, found:" + String.valueOf(date));
        }
    }
}
